import plotly.offline as pyo
from plotly.graph_objs import *
import chart_studio.plotly as py
import pandas as pd
from pandas import DataFrame
pyo.offline.init_notebook_mode()
ethPie = py.get_figure("rmuir", 263)
pyo.iplot(ethPie)
ethPie['data'][0].update({'marker' : {'colors' : ["rgb(12,192,170)",
"rgb(190,252,250)",
"rgb(77,194,84)",
"rgb(211,238,128)",
"rgb(97,167,193)"]}})
ethPie['data'][0]['marker'].update({'line' : {'color' : '#333', 'width' : 1}})
pyo.iplot(ethPie)
ethPie['data'][0].update({'pull' : 1})
pyo.iplot(ethPie)
ethPie['data'][0].update({'pull' : 0.1})
pyo.iplot(ethPie)
ethPie['data'][0].update({'pull' : [0, 0, 0.2, 0, 0]})
pyo.iplot(ethPie)
ethPie['data'][0]
Pie({
'direction': 'clockwise',
'labels': [White, Other, Not known, Black, Asian],
'marker': {'colors': [rgb(12,192,170), rgb(190,252,250), rgb(77,194,84),
rgb(211,238,128), rgb(97,167,193)],
'line': {'color': '#333', 'width': 1}},
'pull': [0, 0, 0.2, 0, 0],
'sort': True,
'values': [1418685.0, 84525.0, 33290.0, 117460.0, 175240.0]
})
labelValues = dict(zip(ethPie['data'][0]['labels'], ethPie['data'][0]['values']))
labelValues
{'White': 1418685.0,
'Other': 84525.0,
'Not known': 33290.0,
'Black': 117460.0,
'Asian': 175240.0}
newLabels = []
newValues = []
for w in sorted(labelValues, key=labelValues.get, reverse=True):
label = w
value = labelValues[w]
newLabels.append(label)
newValues.append(value)
newLabels, newValues
(['White', 'Asian', 'Black', 'Other', 'Not known'], [1418685.0, 175240.0, 117460.0, 84525.0, 33290.0])
ethPie['data'][0]['labels'] = newLabels
ethPie['data'][0]['values'] = newValues
pyo.iplot(ethPie)
ethPie['data'][0].update({'pull' : [0,0,0,0,0.5]})
pyo.iplot(ethPie)